<?php

namespace app\common\model\mysql;

use think\Model;

class SysLogininfor extends Model
{

    //添加登录日志
    public function addLogininfor($data){
        $this->save($data);
        return true;
    }

    /**
     * 查询登录日志列表
     * @param $where
     * @param $field
     * @return SysPost[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getNormalLogininforList($where, $field,$limit,$page,$order){
        if(empty($order)){
            $order = [
                "login_time" =>"desc",
            ];
        }
        $result = $this->where($where)->field($field)->order($order)
            ->paginate([
                'list_rows' => $limit,
                'page' => $page,
            ]);
        return $result;
    }

    public function DellogininforIds($ids){
        if(empty($ids)){
            return false;
        }
        $where = [
            ['info_id', 'in', $ids]
        ];
        $saveData = [
            'del_flag'=>2
        ];
        $result = $this->where($where)->save($saveData);
        return $result;
    }

    public function logininforCleanModel(){
        $where = [
            ['del_flag', '=', 0]
        ];
        $result = $this->where($where)->update(['del_flag' => 2]);
        return $result;
    }
}
